<template>
  <div class="goods-container">
    <!-- 左侧图片区域 -->
    <div class="left">
      <div class="custom-control custom-checkbox">
        <input
          type="checkbox"
          class="custom-control-input"
          :checked="item.goods_state"
          :id="item.id"
          @change="$store.commit('cart/updateState', item.id)"
        />
        <label class="custom-control-label" :for="item.id">
          <img :src="item.goods_img" class="avatar" alt="" />
        </label>
      </div>
    </div>
    <!-- 右侧商品区域 -->
    <div class="right">
      <!-- 标题 -->
      <div class="title">{{ item.goods_name }}</div>
      <div class="info">
        <!-- 单价 -->
        <span class="price">￥{{ item.goods_price }}</span>
        <div class="btns">
          <!-- 按钮区域 -->
          <button
            class="btn btn-light"
            @click="$store.commit('cart/updateCount', { id: item.id, val: -1 })"
          >
            -
          </button>
          <span class="count">{{ item.goods_count }}</span>
          <button
            class="btn btn-light"
            @click="$store.commit('cart/updateCount', { id: item.id, val: 1 })"
          >
            +
          </button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'EsGoods',
  props: {
    item: Object
  }
}
</script>

<style lang="less" scoped>
.goods-container {
  display: flex;
  padding: 10px;
  + .goods-container {
    border-top: 1px solid #f8f8f8;
  }
  .left {
    .avatar {
      width: 100px;
      height: 100px;
    }
    margin-right: 10px;
  }
  .right {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    flex: 1;
    .title {
      font-weight: bold;
    }
    .info {
      display: flex;
      justify-content: space-between;
      align-items: center;
      .price {
        color: red;
        font-weight: bold;
      }
      .btns {
        .count {
          display: inline-block;
          width: 30px;
          text-align: center;
        }
      }
    }
  }
}

.custom-control-label::before,
.custom-control-label::after {
  top: 3.6rem;
}
</style>
